<template>
	<view class="home">
		<view class="home-container">
			<Banner :list="swiperData"></Banner>
			<SubCategory :list="menusData"></SubCategory>
			<News :list="newsData"></News>
			<Promotion :list="promotionData"></Promotion>
			<NewProduct :list="productListData.cc"></NewProduct>
			<RecommendProduct :list="productListData.aa"></RecommendProduct>
		</view>
	</view>
</template>

<script>
	import Banner from './components/Banner'
	import SubCategory from './components/SubCategory'
	import News from './components/News'
	import Promotion from './components/Promotion'
	import NewProduct from './components/NewProduct'
	import RecommendProduct from './components/RecommendProduct'

	import { homeData as homeDataApi } from '@/api/home'
	const app = getApp()
	console.log(app)
	export default {
		components: {
			Banner,
			SubCategory,
			News,
			Promotion,
			NewProduct,
			RecommendProduct
		},
		data() {
			return {
				swiperData: {},
				menusData: {},
				newsData: {},
				promotionData: {},
				newProductData: {},
				productListData: {}
			}
		},
		onLoad() {
			this._getHomeData()
		},
		methods: {
			async _getHomeData () {
				const { status, data, msg } = await homeDataApi()
				if (status === this.API_STATUS_CODE.SUCCESS) {
					console.log(data)
					this.swiperData = data.swiperBg.default
					this.menusData = data.menus.default
					this.newsData = data.news.default
					this.promotionData = data.activity.default
					this.productListData = data.goodList
					app._initTabBar(data.tabBar.default)
				} else {
					uni.showToast({
						icon: 'none',
						title: '首页数据获取失败，请刷新重试',
						duration: 3000
					})
				}
			}
		}
	}
</script>

<style>
</style>
